package com.hqyj.paimaisys.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class QuartzConfig {

    //配置JobDetail
    @Bean
    public JobDetail printTimeJob(){
        JobDetail detail = JobBuilder.newJob(DateTimeJob.class)
                .withIdentity("DateTimeJob")
                .usingJobData("msg","通过Quartz启动的任务")
                .storeDurably(true)
                .build();
        return detail;
    }

    //配置任务触发器Triger
    @Bean
    public Trigger printTimeTrigger(){
        CronScheduleBuilder csb = CronScheduleBuilder.cronSchedule("0/1 * * * * ?");
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(printTimeJob())
                .withIdentity("DateTimeTrigger")
                .withSchedule(csb)
                .build();
        return trigger;
    }
}